class ProductCategoryController {

    ProductService productService
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ productCategoryInstanceList: ProductCategory.list( params ),
          roots:productService.findRoots()]
    }

    def show = {
        def productCategoryInstance = ProductCategory.get( params.id )

        if(!productCategoryInstance) {
            flash.message = "ProductCategory not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ productCategoryInstance : productCategoryInstance ] }
    }

    def delete = {
        def productCategoryInstance = ProductCategory.get( params.id )
        if(productCategoryInstance) {
            productCategoryInstance.delete()
            flash.message = "ProductCategory ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "ProductCategory not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def productCategoryInstance = ProductCategory.get( params.id )

        if(!productCategoryInstance) {
            flash.message = "ProductCategory not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ productCategoryInstance : productCategoryInstance ]
        }
    }

    def update = {
        def productCategoryInstance = ProductCategory.get( params.id )
        if(productCategoryInstance) {
            productCategoryInstance.properties = params
            if(!productCategoryInstance.hasErrors() && productCategoryInstance.save()) {
                flash.message = "ProductCategory ${params.id} updated"
                redirect(action:show,id:productCategoryInstance.id)
            }
            else {
                render(view:'edit',model:[productCategoryInstance:productCategoryInstance])
            }
        }
        else {
            flash.message = "ProductCategory not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def productCategoryInstance = new ProductCategory()
        productCategoryInstance.properties = params
        return ['productCategoryInstance':productCategoryInstance]
    }

    def save = {
        def productCategoryInstance = new ProductCategory(params)
        if(!productCategoryInstance.hasErrors() && productCategoryInstance.save()) {
            flash.message = "ProductCategory ${productCategoryInstance.id} created"
            redirect(action:show,id:productCategoryInstance.id)
        }
        else {
            render(view:'create',model:[productCategoryInstance:productCategoryInstance])
        }
    }
}
